// 活动首页
jQuery(document).ready(function() {
	var imgObj=jQuery("img");
	var imgNum=imgObj.length;
	imgObj.each(function(i,n){
		var thisObj=jQuery(this);
		jQuery("<img />").attr("src",thisObj.attr("src")).load(function(){
			imgNum--;
			if(imgNum<=0){
				jQuery(".wait").animate({
					"top":-jQuery(window).height()+"px"
				},"slow",function(){
					jQuery(this).remove();
				});
				setW();
				setT();
				return false;
			}
		});
	});
	
    // 设置 page 的宽度
	jQuery(window).resize(function(){setW();setT();});
	
	// 左右滑动
	var nowpage = 0;
	jQuery(".page_0,.page_1,.page_2").swipe({
		swipe:function(event, direction, distance, duration, fingerCount) {
			var page_obj = jQuery(".pageList").find(".page");
			var page_w = page_obj.eq(0).width();
			var page_index = page_obj.length - 1 ;
			if( direction == "left" ){
				nowpage = nowpage + 1;
			}/* else if( direction == "right" ){
				nowpage = nowpage - 1;
			}*/
			nowpage = nowpage > 3 ? nowpage = 3 : nowpage < 0 ? nowpage = 0 : nowpage ;
			jQuery(".pageList").animate({"left":nowpage * -100 + "%"},400);
			
			
		}
	});
	
	
	
	// 关闭二维码弹窗
	jQuery(".closeBtn").bind("click",function(){
		closeErweima();
	});
	
	// 打开二维码弹窗
	//jQuery(".taoPiaoBtn").bind("click",function(){
	//	operErweima();
	//});
	
	// 打开二维码弹窗
	function operErweima(){
		jQuery(".tcBg").fadeIn();
		jQuery(".tc").animate({
			"margin-top":"-161px",
			"opacity":"1"
		},"slow");
	}
	
	// 关闭二维码弹窗
	function closeErweima(){
		jQuery(".tcBg").fadeOut();
		jQuery(".tc").animate({
			"margin-top":"-111px",
			"opacity":"0"
		},"slow",function(){
			jQuery(this).css("margin-top","-211px");
		});
	}
	
	// 设置 page 的宽度
	function setW(){
        var w_val = jQuery(".wrapCen").width();
        var pageList_obj = jQuery(".pageList");
        var page_obj = pageList_obj.find(".page");
        pageList_obj.width((w_val*page_obj.length)+"px");
        page_obj.width(w_val+"px");
		
		// 活动规则
		var hdgz_obj = jQuery(".hdgz");
		var font_size = parseInt(hdgz_obj.find("p").css("font-size"));
		var img_w = 640;
		var img_h = 1008;
		var b_num = w_val / img_w;
		var setT = jQuery(".page_2").find(".b").offset().top;
		var img_dang_h = b_num * img_h;
		var topNum = ( 0.385142 * img_dang_h ) + setT;
		hdgz_obj.css({
			"top":topNum+"px"
		}).find("p").css({
			"font-size":( font_size * b_num ) + "px"
		});
	}
	
	// 商家列表页
	function setT(){
		var w_height = jQuery(window).height();
		var merListCen_obj = jQuery(".merListCen");
		var topNum = ( 0.252976 * w_height );
		merListCen_obj.css({
			"top":topNum+"px",
		});
	}
});